<script>
const projectTagValue = tyRoot.getExportResource('src/modules/rpm/business-module/project/components/project-tag-value.vue').default;
export default{
  name: 'ProjectCreate',
  components: { projectTagValue }
}
</script>

<script setup>
// import projectTagValue from './project-tag-value';
// const projectTagValue = tyRoot.getExportResource('src/modules/rpm/business-module/project/components/project-tag-value.vue').default;
// import { useProjectEdit, createProps, useOverride } from './composables/project-edit';
import { useProjectEdit, createProps, useOverride } from './composables/project-edit.js';
import basic from '@common/basic';
import {watch} from 'vue';
const attrConfigurationForm = basic.getExportResource('@/basic/business-modules/attr-configuration-form/attr-configuration-form.vue').default;
// defineOptions({
//   name: 'ProjectCreate',
//   components: { projectTagValue }
// });
const props = defineProps(createProps());
const {
  formData,
  setComponentRef,
  conponentRefs,
  activeNames,
  list,
  systemList,
  formRef,
  ibaForm,
  tyProjectForm,
  isAddparameter,
  valideIbaForm,
  rules,
  systemFormList,
  basicFormList
} = (useOverride || useProjectEdit)(props);
console.log(basicFormList.value);
watch(
  [
    () => tyProjectForm.value?.formData,
    () => basicFormList.value
  ],
  ([newTyForm, newBasicForm]) => {
    // 处理 tyProjectForm.formData
    if (newTyForm && newTyForm.length) {
      newTyForm.forEach(item => {
        if (item.name === '密级') {
          item.showStatus = '3';
          console.log('✅ tyProjectForm 密级处理:', item);
        }
      });
    }

    // 处理 basicFormList
    if (newBasicForm && newBasicForm.length) {
      newBasicForm.forEach(item => {
        if (item.label === '项目名称' || item.label === '工期' || item.label === '阶段' || item.label === '项目密级' || item.label === '项目状态' || item.label === '附件' || item.label === '描述') {
          item.col = 0;
          console.log('✅ basicFormList', item);
          // 你可以在这里做其他逻辑
        }
      });
    }
  },
  { immediate: true, deep: true }
);
defineExpose({
  formRef,
  formData,
  conponentRefs,
  valideIbaForm
});
</script>

<template>
  <ty-plm-form
    ref="formRef"
    :options="{
      model: formData,
      rules,
      labelPosition: 'right',
      labelWidth: '120px',
      refName: 'formRef'
    }"
  >
    <ty-plm-collapse :list="list" :group="true" v-model="activeNames">
      <template #basic>
        <el-row>
          <el-col v-for="item in basicFormList" :key="item.prop" :span="item.col">
            <ty-plm-form-item :label="item.label" :prop="item.prop">
              <component
                v-if="item.componentName"
                :is="item.componentName"
                :ref="
                  el => {
                    if (item.refName) {
                      setComponentRef(item.refName, el);
                    }
                  }
                "
                v-model="formData[item.prop]"
                :options="item.options || {}"
                v-on="item.events || {}"
                v-bind="item.attrs || {}"
              ></component>
            </ty-plm-form-item>
          </el-col>
        </el-row>
      </template>
    </ty-plm-collapse>
    <attr-configuration-form
      ref="ibaForm"
      :form="tyProjectForm"
      class="task-project"
      :isAddparameter="isAddparameter"
      labelWidth="120px"
      v-if="tyProjectForm?.formData.length"
      :col="8"
    />
    <ty-plm-collapse :list="systemList" :group="true" v-model="activeNames">
      <template #system>
        <el-row>
          <el-col v-for="item in systemFormList" :key="item.prop" :span="item.col">
            <ty-plm-form-item :label="item.label" :prop="item.prop">
              <component
                v-if="item.componentName"
                :is="item.componentName"
                v-model="formData[item.prop]"
                :options="item.options || {}"
                :style="item.styles || {}"
                v-on="item.events || {}"
              ></component>
            </ty-plm-form-item>
          </el-col>
        </el-row>
      </template>
    </ty-plm-collapse>
  </ty-plm-form>
</template>

<style lang="scss" scoped>
:deep(.el-input__suffix) {
  .el-input__suffix-inner {
    color: black;
  }
}
:deep(.ant-select) {
  width: 100%;
}
</style>
